'''
Created on Apr 11, 2012
TC ID: 5007
Desc: Kiem thu chuc nang sua thong tin khoa hoc
@author: lavang
'''
import HTMLTestRunner
import time
import unittest
from Functions.globalFunc import preCondition, endCondition, readData
from Functions.loginPageFunc import login
from Functions.coursesFunc import clickOnCourse, createCourse,\
    clickOnSubmit, verifyCourseCreatedSuccessfully, clickOnCourseName


username=readData("username")
password=readData("password")
tm_courseName=readData("courseName",index=2)
tm_newcourseName=readData("courseName",index=1)
tm_categories=readData("categoriesLesson")
tm_language="Dansk"
tm_price=20
class Ecom_5007(unittest.TestCase):


    def setUp(self):
        preCondition(self)

    def test_Ecom_5007(self):
        print "Buoc 1: Dang nhap vao website"
        login(self,username,password)
        
        print "Buoc 2: Click vao courses"
        clickOnCourse(self)
        
        print "Buoc 3: Click vao khoa hoc muon sua thong tin "
        clickOnCourseName(self,tm_courseName)
        
        print "Buoc 4: Nhap thong tin"
        createCourse(self,courseName=tm_newcourseName,categories=tm_categories,language=tm_language,price=tm_price)
        
        print "Buoc 5: Click Submit"
        clickOnSubmit(self)
        
        print "Buoc 6: Xac nhan sua thong tin khoa hoc thanh cong"
        self.assertTrue(verifyCourseCreatedSuccessfully(self,tm_newcourseName), "Failed!")
        print "Passed: Khoa hoc duoc sua thong tin"
    
    def tearDown(self):
        endCondition(self)
        



if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5007)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang sua thong tin khoa hoc'
                    )
    runner.run(suite)